home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-05-20 | 4.5 KB | 90 lines | [TEXT/R*ch] |
- FileBrowser:
-
- I've been thinking about doing some things with hierarchial list boxes, but i've
- found them a bit limited for anything that goes over two levels deep, for several
- reasons:
- You need to work to get the display of nested items to look good.
- You can't insert folders, but can only add them to the end of the box.
- You can't code whether the folder is opened or closed when added.
- You can't trigger the open or close events via code.
-
- So, i've decided to play around with creating the next best thing - something
- that will act something like a hierarchial box in terms of basic display and
- functionality. You can think of double clicking on a folder the equivalent of
- opening the disclosure triangle and double clicking the back arrow as the
- equivalent of closing it.
-
- To provide a demonstration using a hierarchial structure that everybody will
- have, i decided to use the file system. i modeled the window a bit on the Next
- Browser, but it is very limited in comparison. Still, as you could probably tell
- by looking at the code, a lot of it is easy to reuse, so it would be simple to
- add more listboxes and expand it. I've also noted where you could add the ability
- to launch non-directories on double clicking. As an added bonus, i've added drag
- and drop to help anybody who's having trouble with that.
-
-
- Practicalities:
-
- Both list boxes have a parallel array of folder items. Both the contents of
- the list boxes and the folder item array are altered within the two methods,
- which accept a folder item as their parameter. This helps keep everything
- nicely in synch.
-
- The open event of the window loads all the volumes into the first list box.
- This is also done when the "Root" button is hit and, finally, when the back
- button is hit while in the root of any volume (more on this later).
-
- Double clicking ignores a non-directory. If it is a directory, what happens
- depends on which list box it's in. In box1, the directory is handed to the
- box2 method, which puts its contents in box2. This happens even if something
- else is already in box2. If you double click a box2 directory, it hands a
- its parent directory to the box1 method, essentially swapping box2 into box1.
- Next, it sends the box2 method the directory, putting its contents there.
-
- In addition, the back button is added by the box1 method. It clears box2,
- gets the parent of the parent of an item in box1, and sends it to the box1
- method. If you're in the root level of a volume, though this will throw an
- error (there's no parent for a volume). So, in the box1.doubleClick event,
- i added an exception trap. If this occurs, it simply does the same thing as
- the "Root" button does (and doesn't add a back arrow).
-
- Dropping is accepted on a window-wide basis. When a folder item is dropped,
- everything is cleared and it's handed to box 1. If the item is a directory,
- it's handed to the box1 method. If not, its parent is.
-
- Dragging is quite straightforward from list boxes, since the drag object is
- created for you. The text and folder item properties of the drag item are
- populated with from the text in the listbox or the corresponding array item,
- respectively. In box1, a check is thrown in to make sure you don't allow
- the user to try to drag the back arrow.
-
-
- Implications for general use:
-
- Aside from some interesting methods and the use of an exception trap, the most
- important thing here is that these methods are very extensible. As i mentioned
- above, it would be very easy to expand this to multiple listboxes by slightly
- altering the methods. In fact, the methods for any listboxes between the first
- and last would be identical, allowing for a control array and dynamically created
- controls to give this a great deal of flexibility. In the other direction, you
- could easily hand a directory double clicked in box1 to its own method, opening
- it up in the same listbox. This would allow for custom open/save type dialogs.
- By querying the .type property, you could add custom icons for files, applications,
- etc.
-
- In addition, you can make your own objects which will fit into these methods with
- little modification. Just make sure your objects have the following properties:
- name as string
- count as integer
- directory as boolean
- item (0) as yourObject
- After that, change the arrays to containing yourObject and the two methods to
- accpeting yourObject as a parameter and you're in business.
-
-
- Enjoy!
- Jay Timmer
- jtimmer@tuna.net
- For personal use, this code is free. If you use the code in any commercial
- programs, i get a license for a copy.
-